﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Vkontakte.Api
{
	[XmlRoot("response")]
	public sealed class ListingResponce
	{
		[XmlAttribute("list")]
		public bool List { get; set; }

		[XmlElement("count")]
		public int Count { get; set; }

		[XmlElement("user")]
		public Person[] Persons;

		[XmlElement("group")]
		public Group[] Groups;

		[XmlElement("activity")]
		public ActivityHistoryItem[] Activities;

		[XmlElement("album")]
		public PhotoAlbum[] PhotoAlbums;

		[XmlElement("photo")]
		public Photo[] Photos;

		[XmlElement( "country" )]
		public Country[] Countries;

		[XmlElement( "message" )]
		public Message[] Messages;

		[XmlElement( "audio" )]
		public AudioRecord[] AudioRecords;

		[XmlElement( "city" )]
		public City[] Cities;

		[XmlElement( "type" )]
		public PlaceType[] PlaceTypes;

		[XmlElement("video")]
		public Video[] Videos;
	}

	public sealed class Message
	{
		[XmlElement("body")]
		public string Body{ get; set;}
		[XmlElement("title")]
		public string Title{ get; set;}
		[XmlArray("attachments")]
		[XmlArrayItem("item")]
		public string[] Attachments{ get; set;}
		[XmlElement("date")]
		public long Date{ get; set;}
		[XmlElement("uid")]
		public long UserID{ get; set;}
		[XmlElement("mid")]
		public long MessageID{ get; set;}
		[XmlElement("read_state")]
		public ReadState ReadState { get; set; }
		[XmlElement("out")]
		public MessageType Out { get; set; }
	}

	public sealed class Country
	{
		[XmlElement("cid")]
		public int CountryID { get; set; }
		[XmlElement("title")]
		public string Title { get; set; }
	}

	public sealed class City
	{
		[XmlElement("cid")]
		public int CityID { get; set; }
		[XmlElement("title")]
		public string Title { get; set; }
	}

	public sealed class Video
	{
		[XmlElement("vid")]
		public long VideoID { get; set; }
		[XmlElement("owner_id")]
		public string OwnerID { get; set; }
		[XmlElement("title")]
		public string Title { get; set; }
		[XmlElement("description")]
		public string Description { get; set; }
		[XmlElement("duration")]
		public int Duration { get; set; }
		[XmlElement("link")]
		public string Link { get; set; }
		[XmlElement("image")]
		public string Image { get; set; }
		[XmlElement("date")]
		public long Date { get; set; }
	}

	public sealed class Photo
	{
		[XmlElement("pid")]
		public long PhotoID { get; set; }
		[XmlElement("aid")]
		public long AlbumID { get; set; }
		[XmlElement("owner_id")]
		public long OwnerID { get; set; }
		[XmlElement("src")]
		public string Source { get; set; }
		[XmlElement("src_big")]
		public string SourceBig { get; set; }
		[XmlElement("src_small")]
		public string SourceSmall { get; set; }
		[XmlElement("src_xbig")]
		public string SourceXBig { get; set; }
		[XmlElement("src_xxbig")]
		public string SourceXXBig { get; set; }
		[XmlElement("created")]
		public long Created { get; set; }
	}

	public sealed class PhotoAlbum
	{
		[XmlElement("aid")]
		public long AlbumID { get; set; }
		[XmlElement("thumb_id")]
		public long ThumbID { get; set; }
		[XmlElement("owner_id")]
		public long OwnerID { get; set; }
		[XmlElement("title")]
		public string Title { get; set; }
		[XmlElement("description")]
		public string Description { get; set; }
		[XmlElement("created")]
		public long Created { get; set; }
		[XmlElement("updated")]
		public long Updated { get; set; }
		[XmlElement("size")]
		public int Size { get; set; }
		[XmlElement("privacy")]
		public int Privacy { get; set; }
	}

	[XmlRoot("error")]
	public sealed class ErrorResponce
	{
		[XmlElement("error_code")]
		public ApiError Error { get; set; }

		[XmlElement("error_msg")]
		public string ErrorMessage { get; set; }
	}

	public sealed class AudioRecord
	{
		[XmlElement("aid")]
		public long AudioID{ get; set;}
		[XmlElement("owner_id")]
		public long UserID{ get; set;}
		[XmlElement("artist")]
		public string Artist{ get; set;}
		[XmlElement("title")]
		public string Title{ get; set;}
		[XmlElement("duration")]
		public int Duration{ get; set;}
		[XmlElement("url")]
		public string Url{ get; set;}
		[XmlElement("lyrics_id")]
		public long LyricsID{ get; set;}
	}

	public sealed class PlaceType
	{
		[XmlElement("tid")]
		public int TypeID{ get; set;}
		[XmlElement("title")]
		public string Title{ get; set;}
		[XmlElement("icon")]
		public string Icon{ get; set;}
	}

	public sealed class ActivityHistoryItem
	{
		[XmlElement("id")]
		public long ID { get; set; }
		[XmlElement("text")]
		public string Text { get; set; }
		[XmlElement("created")]
		public long Created { get; set; }
	}

	[XmlRoot("response")]
	public sealed class ActivityResponce
	{
		[XmlElement("time")]
		public long Time { get; set; }
		[XmlElement("activity")]
		public string Activity { get; set; }
		[XmlElement("id")]
		public long ID { get; set; }
		[XmlElement("local_id")]
		public long LocalID { get; set; }
		[XmlElement("flags")]
		public int Flags { get; set;}
		[XmlElement("user_id")]
		public long UserID { get; set; }
	}

	public class Person
	{
		[XmlElement("uid")]
		public long UserID { get; set; }

		[XmlElement("first_name")]
		public string FirstName { get; set; }

		[XmlElement("last_name")]
		public string LastName { get; set; }

		[XmlElement("nickname")]
		public string NickName { get; set; }

		[XmlElement("online")]
		public int Online { get; set; }

		[XmlElement("lists")]
		public GroupList Groups { get; set; }

		[XmlElement("sex")]
		public Sex Sex { get; set; }

		[XmlElement("domain")]
		public string Domain { get; set; }

		[XmlElement("city")]
		public long City { get; set; }

		[XmlElement("country")]
		public long Country { get; set; }

		[XmlElement("bdate")]
		public string BirthDate { get; set; }

		[XmlElement("timezone")]
		public string TimeZone { get; set; }

		[XmlElement("photo")]
		public string Photo { get; set; }

		[XmlElement("photo_medium")]
		public string PhotoMedium { get; set; }

		[XmlElement("photo_big")]
		public string PhotoBig { get; set; }

		[XmlElement("photo_rec")]
		public string PhotoRec { get; set; }
		
		[XmlElement("home_phone")]
		public string HomePhone { get; set; }

		[XmlElement("mobile_phone")]
		public string MobilePhone { get; set; }

		[XmlElement("university")]
		public int University { get; set; }

		[XmlElement("university_name")]
		public string UniversityName { get; set; }

		[XmlElement("faculty")]
		public string Faculty { get; set; }

		[XmlElement("faculty_name")]
		public string FacultyName { get; set; }

		[XmlElement("graduation")]
		public string Graduation { get; set; }

		[XmlElement("rate")]
		public int Rate { get; set; }

		public override string ToString()
		{
			return string.Format("{0} {1} {2} {3}", FirstName, NickName, LastName, Online);
		}
	}


	public class Group
	{
		[XmlElement("gid")]
		public long GroupID { get; set; }
		[XmlElement("name")]
		public string Name { get; set; }
		[XmlElement("photo")]
		public string Photo { get; set; }
		[XmlElement("is_closed")]
		public int IsClosed { get; set; }
	}
	
	[Serializable]
	public class GroupList
	{
		[XmlArray("list")]
		[XmlArrayItem("item")]
		public int[] IDs { get; set; }
	}

	public enum Sex
	{
		[XmlEnum("0")]
		None,
		[XmlEnum("1")]
		Female,
		[XmlEnum("2")]
		Male,
		[XmlEnum("3")]
		ThreeTimesAtDay
	}

	public enum MessageType
	{
		[XmlEnum("0")]
		Incoming,
		[XmlEnum("1")]
		Outgoing
	}

	public enum ReadState
	{
		[XmlEnum("0")]
		Unreaded,
		[XmlEnum("1")]
		Readed
	}

	public class FriendsList
	{
		public int ID { get; set; }
		public string Name { get; set; }
	}

	[XmlRoot("response")]
	public class LongPollServerData
	{
		[XmlElement("key")]
		public string Key{ get; set;}
		[XmlElement("server")]
		public string Server{ get; set;}
		[XmlElement("ts")]
		public long Timestamp{ get; set;}
	}
}
